﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<GabageFactory.Models.EventRecord>" %>
<%@ Import Namespace="System.Collections.Generic" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	创建事件
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        function setCenter(Xelement) {
            var parent = Xelement.parentNode;
            parent.style.position = "relative";
            Xelement.style.position = "absolute";
            var left = (parent.clientWidth - Xelement.clientWidth) / 2;
            var top = (parent.clientHeight - Xelement.clientHeight) / 2;
            Xelement.style.left = left + "px";
            Xelement.style.top = top + "px";
        }
    </script>
    
    <% 
        User user = (User)ViewData["user"];
        EventDailyRecord dailyRecord = (EventDailyRecord) ViewData["dailyRecord"];
        using (Html.BeginForm())
    {%>
        <%= Html.ValidationSummary(true) %>
        <%= Html.HiddenFor(model => model.Id) %>
            
    <table cellpadding="4" cellspacing="0" class="com_detail_table" style="padding-top:2px; width:756px;">
        <tr>
            <td class="lab" style="width:90px;">选择现场：</td>
            <td>
                <%if ((bool)ViewData["showFactory"])
                {%>
            <%= Html.DropDownList("FactoryID", ViewData["factories"] as List<SelectListItem>, "请选择公司", new { onchange = "showStacks();" })%>
            <span style="margin-left:20px"></span>
            <%
                }
                else
                {
            %>
            <%=Html.Hidden("FactoryID", Model.FactoryID)%>
            <%
                }
            %>
                <span id="stackList"><%= Html.DropDownList("stackId", ViewData["stacksAndTailingponds"] as List<SelectListItem>, "请选择")%></span>
            </td>
        </tr>
        <tr>
            <td class="lab">事件类别：</td>
            <td>
                <select id="Type" name="Type">
                    <option value="0">请选择类别</option>
                    <option value="1" <%if(Model.Type == 1){ %> selected="selected" <%} %>>输浆管</option>
                    <option value="2" <%if(Model.Type == 2){ %> selected="selected" <%} %>>回水管</option>
                    <option value="3" <%if(Model.Type == 3){ %> selected="selected" <%} %>>泵房</option>
                    <option value="4" <%if(Model.Type == 4){ %> selected="selected" <%} %>>虹吸管</option>
                    <option value="5" <%if(Model.Type == 5){ %> selected="selected" <%} %>>斜槽</option>
                    <option value="6" <%if(Model.Type == 6){ %> selected="selected" <%} %>>截洪沟</option>
                    <option value="7" <%if(Model.Type == 7){ %> selected="selected" <%} %>>初期堤</option>
                    <option value="8" <%if(Model.Type == 8){ %> selected="selected" <%} %>>堆积坝</option>
                    <option value="9" <%if(Model.Type == 9){ %> selected="selected" <%} %>>HDPE膜</option>
                    <option value="10" <%if(Model.Type == 10){ %> selected="selected" <%} %>>山坡</option>
                    <option value="11" <%if(Model.Type == 11){ %> selected="selected" <%} %>>底部导渗</option>
                    <option value="12" <%if(Model.Type == 12){ %> selected="selected" <%} %>>堆体导渗</option>
                    <option value="13" <%if(Model.Type == 13){ %> selected="selected" <%} %>>排洪设施</option>
                    <option value="14" <%if(Model.Type == 14){ %> selected="selected" <%} %>>机械</option>
                    <option value="15" <%if(Model.Type == 15){ %> selected="selected" <%} %>>其他</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="lab">事件级别：</td>
            <td>
                <select id="Priority" name="Priority">
                    <option value="1" <%if(Model.Priority == 1){ %> selected="selected" <%} %>>非常紧急</option>
                    <option value="2" <%if(Model.Priority == 2){ %> selected="selected" <%} %>>紧急</option>
                    <option value="3" <%if(Model.Priority == 3){ %> selected="selected" <%} %>>一般紧急</option>
                    <option value="4" <%if(Model.Priority == 4 || Model.Priority == 0){ %> selected="selected" <%} %>>普通</option>
                    <option value="5" <%if(Model.Priority == 5){ %> selected="selected" <%} %>>无限制</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="lab">上报时间：</td>
            <td>
                <%=Html.TextBoxFor(model => model.OccurredDate)%>
                &nbsp;&nbsp;上报人：<%=user.RealName + "(" + user.Name + ")"%>
            </td>
        </tr>
        <tr>
            <td class="lab">事件名称：</td>
            <td><%=Html.TextBoxFor(model => model.Name, new { style = "width:500px"})%></td>
        </tr>
        <tr>
            <td class="lab">事件内容：</td>
            <td><%=Html.TextArea("EventDesc", dailyRecord.Description, new { rows = 5, cols = 80 })%></td>
        </tr>
        <tr>
           <td class="lab">现场图片：</td>
           <td>
                <div id="addPicButton"><input type="file" name="file_upload" id="file_upload" /></div>
           </td>
        </tr>
        <tr>
           <td class="lab">&nbsp;</td>
           <td id="pics">
                <div id="pic1Area" style="<% if (string.IsNullOrEmpty(dailyRecord.Pic1)) {%>display:none;<%} %>clear:both;margin-top:10px; padding:5px 4px 0px 4px; border:1px solid #e4e4e4; overflow:hidden; zoom:1;background-color:#efefef;">
                  <input type="hidden" id="picPath1" name="picPath1" value="<%=dailyRecord.Pic1 %>" />
                  <div style="border:1px solid #e4e4e4;float:left;width:100px;height:75px;text-align:center;line-height:75px; background-color:#fff;"><img id="pic1" src="<% if (string.IsNullOrEmpty(dailyRecord.Pic1)) {%>../../Content/empty.png<%}else{ %><%=Url.Content(dailyRecord.Pic1) %><%} %>" alt="" onload="setCenter(this)" class="thumbnail" /></div>
                  <div style="margin-left:10px;float:left">
                      <div style="float:left"><textarea id="picDes1" name="picDes1" rows="2" cols="48" style="height:70px"><%= dailyRecord.Pic1_desc%></textarea></div>
                      <div style="float:left">
                        <p style=" margin-bottom:10px;">
                        <input type="button" class="uploadify-button2" value="删  除" onclick="delPic(1);" />
                        </p>
                        <input type="file" name="file_upload1" id="file_upload1" />
                      </div>
                  </div>
                </div>
                <div id="pic2Area" style="<% if (string.IsNullOrEmpty(dailyRecord.Pic2)) {%>display:none;<%} %>clear:both;margin-top:10px; padding:5px 4px 0px 4px; border:1px solid #e4e4e4; overflow:hidden; zoom:1;background-color:#f4f4f4;">
                  <input type="hidden" id="picPath2" name="picPath2" value="<%=dailyRecord.Pic2 %>" />
                  <div style="border:1px solid #e4e4e4;float:left;width:100px;height:75px;text-align:center;line-height:75px;"><img id="pic2" src="<% if (string.IsNullOrEmpty(dailyRecord.Pic2)) {%>../../Content/empty.png<%}else{ %><%=Url.Content(dailyRecord.Pic2) %><%} %>" alt="" onload="setCenter(this)" class="thumbnail" /></div>
                  <div style="margin-left:10px;float:left">
                      <div style="float:left"><textarea id="picDes2" name="picDes2" rows="5" cols="48" style="height:70px"><%= dailyRecord.Pic2_desc%></textarea></div>
                      <div style="float:left">
                        <p style=" margin-bottom:10px;">
                            <input type="button" class="uploadify-button2" value="删  除" onclick="delPic(2);" />
                        </p>
                      <input type="file" name="file_upload2" id="file_upload2" /></div>
                  </div>
                </div>
                <div id="pic3Area" style="<% if (string.IsNullOrEmpty(dailyRecord.Pic3)) {%>display:none;<%} %>clear:both;margin-top:10px; padding:5px 4px 0px 4px; border:1px solid #e4e4e4; overflow:hidden; zoom:1;background-color:#efefef;">
                  <input type="hidden" id="picPath3" name="picPath3" value="<%=dailyRecord.Pic3 %>" />
                  <div style="border:1px solid #e4e4e4;float:left;width:100px;height:75px;text-align:center;line-height:75px;"><img id="pic3" src="<% if (string.IsNullOrEmpty(dailyRecord.Pic3)) {%>../../Content/empty.png<%}else{ %><%=Url.Content(dailyRecord.Pic3) %><%} %>" alt="" onload="setCenter(this)" class="thumbnail" /></div>
                  <div style="margin-left:10px;float:left">
                      <div style="float:left"><textarea name="picDes3" id="picDes3" rows="5" cols="48" style="height:70px"><%= dailyRecord.Pic3_desc%></textarea></div>
                      <div style="float:left">
                        <p style=" margin-bottom:10px;">
                            <input type="button" class="uploadify-button2" value="删  除" onclick="delPic(3);" />
                        </p>    
                        <input type="file" name="file_upload3" id="file_upload3" /></div>
                  </div>
                </div>
                <div id="pic4Area" style="<% if (string.IsNullOrEmpty(dailyRecord.Pic4)) {%>display:none;<%} %>clear:both;margin-top:10px; padding:5px 4px 0px 4px; border:1px solid #e4e4e4; overflow:hidden; zoom:1;background-color:#f4f4f4;">
                  <input type="hidden" id="picPath4" name="picPath4" value="<%=dailyRecord.Pic4 %>" />
                  <div style="border:1px solid #e4e4e4;float:left;width:100px;height:75px;text-align:center;line-height:75px;"><img id="pic4" src="<% if (string.IsNullOrEmpty(dailyRecord.Pic4)) {%>../../Content/empty.png<%}else{ %><%=Url.Content(dailyRecord.Pic4) %><%} %>" alt="" onload="setCenter(this)" class="thumbnail" /></div>
                  <div style="margin-left:10px;float:left">
                      <div style="float:left"><textarea name="picDes4" id="picDes4" rows="5" cols="48" style="height:70px"><%= dailyRecord.Pic4_desc%></textarea></div>
                      <div style="float:left">
                        <p style=" margin-bottom:10px;">
                            <input type="button" class="uploadify-button2" value="删  除" onclick="delPic(4);" />
                        </p>
                        <input type="file" name="file_upload4" id="file_upload4" />
                      </div>
                  </div>
                </div>
           </td>
        </tr>
    </table>
    
    <div class="submit_btn_area" style="margin-left:104px;">
        <input type="submit" onclick="return validForm();" value="提 交" />
    </div>
    <% } %>



    <script type="text/javascript" src="../../Scripts/jquery.uploadify-3.1.min.js"></script>
    <script type="text/javascript" language="javascript">
        function showStacks() {
            var factoryId = document.getElementById("FactoryID").value;
            if (factoryId == "" || factoryId == 0) return;
            $.ajax({ 
                    type: "POST",
                    url: "<%=Url.Content("~/Modification/ListStacks") %>",
                    data: "factoryId=" + factoryId + "&showType=0",
                    success: function (data) { $("#stackList").html(data);}
            });
        }

        function validForm() {
            if ($("#Name").val() == undefined || $("#Name").val() == null || $("#Name").val() == "") {
                alert("请填写事件名称！");
                $("#Name").focus();
                return false;
            }
            
            var factoryId = document.getElementById("FactoryID").value;
            if (factoryId == 0 || factoryId == "" || factoryId == undefined) {
                alert("请选择公司！");
                document.getElementById("FactoryID").focus();
                return false;
            }

            var stackId = document.getElementById("stackId").value;
            if (stackId == 0 || stackId == "" || stackId == undefined) {
                alert("请选择堆场/尾矿库！");
                document.getElementById("stackId").focus();
                return false;
            }

            if ($("#Type").val() == undefined || $("#Type").val() == null || $("#Type").val() == "0") {
                alert("请选择事件类别！");
                $("#Type").focus();
                return false;
            }

            if ($("#Priority").val() == undefined || $("#Priority").val() == null || $("#Priority").val() == "") {
                alert("请选择事件级别！");
                $("#Priority").focus();
                return false;
            }

            if ($("#EventDesc").val() == undefined || $("#EventDesc").val() == null || $("#EventDesc").val() == "") {
                alert("请填写事件内容！");
                $("#EventDesc").focus();
                return false;
            }
            

            return true;
        }

        
        $('#OccurredDate').datetimepicker({
            showSecond: false,
            timeFormat: 'hh:mm'
        });

        function delFile(filePath) {
            $.ajax({  
                type: "POST",  
                url: '<%=Url.Content("~/Event/DelFile") %>',  
                data: { "file": filePath }
            }).done(function( msg ) {});
        }

        var picNum = <%=dailyRecord.PicNum %>;

        var picFlags = [<%if(string.IsNullOrEmpty(dailyRecord.Pic1)) {%>false<%}else{ %>true<%} %>,<%if(string.IsNullOrEmpty(dailyRecord.Pic2)){%>false<%}else{ %>true<%} %>,<%if(string.IsNullOrEmpty(dailyRecord.Pic3)){ %>false<%}else{ %>true<%} %>,<%if(string.IsNullOrEmpty(dailyRecord.Pic4)){ %>false<%}else{ %>true<%} %>];

        $(function () {
            $("#file_upload").uploadify({
                'fileObjName': 'file',
                'multi': false,
                'buttonText': '添加图片',
                'buttonClass': 'submit_btn_area2',
                'fileSizeLimit': '200KB',
                'fileTypeDesc': 'Jpeg Files',
                'fileTypeExts': '*.jpeg; *.jpg',
                'swf': '<%=Url.Content("~/Content/uploadify.swf") %>',
                'uploader': '<%=Url.Content("~/Event/FileUpload") %>',
                'onUploadSuccess': function (file, data, response) {
                    var result = eval("(" + data + ")");
                    if (result.error != "") {
                        alert(result.error);
                        return;
                    }
                    showPic(result.url);
                },
                'onUploadError': function (file, errorCode, errorMsg, errorString) {
                    alert('添加图片失败，请重新添加');
                }

            });

            $("#file_upload1").uploadify({
                'fileObjName': 'file',
                'multi': false,
                'buttonText': '重新上传',
                'buttonClass': 'submit_btn_area2',
                'fileSizeLimit': '200KB',
                'fileTypeDesc': 'Jpeg Files',
                'fileTypeExts': '*.jpeg; *.jpg',
                'swf': '<%=Url.Content("~/Content/uploadify.swf") %>',
                'uploader': '<%=Url.Content("~/Event/FileUpload") %>',
                'onUploadSuccess': function (file, data, response) {
                    var result = eval("(" + data + ")");
                    if (result.error != "") {
                        alert(result.error);
                        return;
                    }
                    replacePic(1, result.url);
                },
                'onUploadError': function (file, errorCode, errorMsg, errorString) {
                    alert('添加图片失败，请重新添加');
                }

            });

            $("#file_upload2").uploadify({
                'fileObjName': 'file',
                'multi': false,
                'buttonText': '重新上传',
                'buttonClass': 'submit_btn_area2',
                'fileSizeLimit': '200KB',
                'fileTypeDesc': 'Jpeg Files',
                'fileTypeExts': '*.jpeg; *.jpg',
                'swf': '<%=Url.Content("~/Content/uploadify.swf") %>',
                'uploader': '<%=Url.Content("~/Event/FileUpload") %>',
                'onUploadSuccess': function (file, data, response) {
                    var result = eval("(" + data + ")");
                    if (result.error != "") {
                        alert(result.error);
                        return;
                    }
                    replacePic(2, result.url);
                },
                'onUploadError': function (file, errorCode, errorMsg, errorString) {
                    alert('添加图片失败，请重新添加');
                }

            });

            $("#file_upload3").uploadify({
                'fileObjName': 'file',
                'multi': false,
                'buttonText': '重新上传',
                'buttonClass': 'submit_btn_area2',
                'fileSizeLimit': '200KB',
                'fileTypeDesc': 'Jpeg Files',
                'fileTypeExts': '*.jpeg; *.jpg',
                'swf': '<%=Url.Content("~/Content/uploadify.swf") %>',
                'uploader': '<%=Url.Content("~/Event/FileUpload") %>',
                'onUploadSuccess': function (file, data, response) {
                    var result = eval("(" + data + ")");
                    if (result.error != "") {
                        alert(result.error);
                        return;
                    }
                    replacePic(3, result.url);
                },
                'onUploadError': function (file, errorCode, errorMsg, errorString) {
                    alert('添加图片失败，请重新添加');
                }

            });

            $("#file_upload4").uploadify({
                'fileObjName': 'file',
                'multi': false,
                'buttonText': '重新上传',
                'buttonClass': 'submit_btn_area2',
                'fileSizeLimit': '200KB',
                'fileTypeDesc': 'Jpeg Files',
                'fileTypeExts': '*.jpeg; *.jpg',
                'swf': '<%=Url.Content("~/Content/uploadify.swf") %>',
                'uploader': '<%=Url.Content("~/Event/FileUpload") %>',
                'onUploadSuccess': function (file, data, response) {
                    var result = eval("(" + data + ")");
                    if (result.error != "") {
                        alert(result.error);
                        return;
                    }
                    replacePic(4, result.url);
                },
                'onUploadError': function (file, errorCode, errorMsg, errorString) {
                    alert('添加图片失败，请重新添加');
                }

            });
        });

        function delPic(index) {
            picNum--;
            picFlags[index - 1] = false;
            $("#pic" + index + "Area").css("display", "none");
            $("#pic" + index).attr("src", "../../Content/empty.png");
            delFile($("#picPath" + index).val());
            $("#picPath" + index).val("");
            $("#picDes" + index).val("");
            $("#addPicButton").css("display", "");
        }

        function showPic(url) {
            picNum++;
            var i = 0;
            for (i = 0; i < 4; i++) {
                if (picFlags[i] == false) {
                    picFlags[i] = true;
                    $("#pic" + (i + 1) + "Area").css("display", "block");
                    $("#pic" + (i + 1)).attr("src", url);
                    $("#picPath" + (i + 1)).val(url);
                    break;
                }
            }

            if (picNum >= 4) {
                $("#addPicButton").css("display", "none");
            }
        }

        function replacePic(index, url) {
            $("#pic" + index).attr("src", url);
            $("#picPath" + index).val(url);
        }
    </script>
</asp:Content>
